package com.qingfeng.core.dao.qingfeng;

import com.qingfeng.core.aop.exception.HttpException;
import com.qingfeng.core.config.database.BaseMapper;
import com.qingfeng.core.dao.BaseDao;
import com.qingfeng.core.entity.qingfeng.Refund;
import com.qingfeng.core.mapper.qingfeng.RefundMapper;
import com.qingfeng.core.utils.UuidUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Date;

/**
 * @description: 任务
 * @author:LWY
 * @date: 2017/10/16 17:15
 * @modified:
 */

@Repository
public class RefundDao extends BaseDao<Refund> {

    @Autowired
    RefundMapper refundMapper;

    @Override
    protected BaseMapper<Refund> getBaseMapper() {
        return refundMapper;
    }

    /**
     * 保存退款申请
     *
     * @param order_id    订单号
     * @param goods_state 退款时状态（1：未收到货、2：已经收到货）
     * @param rease       退款原因
     * @param instruction 退款说明
     * @return
     */
    public Refund insert(String order_id, Integer goods_state, String rease, String instruction) {
        Refund refund = new Refund();
        String id = UuidUtil.generatorUUID();
        refund.setId(id);
        refund.setOrder_id(order_id);
        refund.setState(1);//未审核状态
        refund.setRease(rease);
        refund.setInstruction(instruction);
        refund.setCreate_time(new Date());
        refund.setGoods_state(goods_state);
        if (super.insert(refund) != 1) {
            throw new HttpException("退款申请失败");
        }
        return refund;
    }
}
